(function() {
	var common = {};
    ///////////////////////////js 全局常量定义  start//////////////////////////////
    common.TYPE_METADATA_LOG="type-fs-metadata-log";
    common.TYPE_METADATA_SM="type-fs-metadata-sm";
    common.TYPE_METADATA_FTP="type-fs-metadata-ftp";
    common.TYPE_METADATA_FASTDFS="type-fs-metadata-fastdfs";
    common.TYPE_METADATA_EMAIL="type-fs-metadata-email";
    common.TYPE_METADATA_REDIS="type-fs-metadata-redis";
    ///////////////////////////js 全局常量定义 end//////////////////////////////
	/**
	 * 
	 * @param {Object} target 目标jq对象
	 * @param {Object} url    跳转地址
	 */
	common.go = function(target, url) {
		$.ajax({
			type : "get",
			url : url,
			dataType : "html",
			success : function(data) {
				target.html(data);
			},
			error : function() {
				target.html('<div class="tc cr pt30">找不到对应页面！</div>');
			}
		});
	};
	common.tab = function(tabs) {
		tabs.find("li[tab]").each(function() {
			$(this).click(function() {
				removeActive();
				$(this).addClass("active");
				var tab = $(this).attr("tab");
				tabs.find('.tab-pane[tab]').each(function() {
					$(this).removeClass("active");
					if (tab == $(this).attr("tab")) {
						$(this).addClass("active");
					}
				})
			})
		});
		function removeActive() {
			tabs.find("li").each(function() {
				$(this).removeClass("active");
			});
		}
	};
	
	common.tabInit = function(tabsOBj) {
		tabsOBj.find("li[tab]").each(function() {
			$(this).click(function() {
				removeActive1();
				$(this).addClass("active");
				var tab = $(this).attr("tab");
				tabsOBj.find('.tab-pane[tab]').each(function() {
					$(this).removeClass("active");
					if (tab == $(this).attr("tab")) {
						$(this).addClass("active");
						var url=$(this).attr("action");
						var target=$(this);
						if(url==''){
							target.html('<div class="tc cr pt30">功能开发中,敬请期待...！</div>');
							return;
						}
						$.ajax({
							type : "get",
							url : url,
							dataType : "html",
							success : function(data) {
								target.html(data);
							},
							error : function() {
								target.html('<div class="tc cr pt30">找不到对应页面！</div>');
							}
						});
					}
				})
			})
		});
		function removeActive1() {
			tabsOBj.find('.tab-pane[tab]').each(function() {
				$(this).empty();
			})
			
			tabsOBj.find("li").each(function() {
				$(this).removeClass("active");
			});
		};
		
		tabsOBj.find("li[tab]").each(function() {
			if($(this).attr('class')=='active'){
				$(this).click();
			}
		});
       //lcy add 2016/10/20 添加提示元素 start
        $(".nav.nav-tabs").append('<div id="id-tips" style="float: right;padding-right: 50px;padding-top: 10px"/>');
       //lcy add 2016/10/20 添加提示元素 end

	};
	
	common.downLoad = function(action) {
		var form = $("<form>");
        form.attr('style', 'display:none');
        form.attr('target', '');
        form.attr('method', 'post');
        //var action='${pageContext.request.contextPath}/edocinfo/export';
        form.attr('action', action);

        var input1 = $('<input>');
        input1.attr('type', 'hidden');
        input1.attr('name', 'item');
        input1.attr('value', JSON.stringify($.serializeObject($('#searchForm'))));

        $('body').append(form);
        form.append(input1);
        
        form.submit();
        form.remove();
	};

    /**
     * 时间选择控件初始化
     * @param timeBtnObj
     * @param queryFun
     */
    common.timeselectInit=function(timeBtnObj,queryFun){
        ////////////////////////初始化时间控件  start/////////////////////
        $('.form_date_s').datetimepicker({
            language : 'zh-CN',
            weekStart : 1,
            todayBtn : 1,
            autoclose : 1,
            todayHighlight : 1,
            startView : 2,
            //minView: 2,
            forceParse : 0,
            pickerPosition : "bottom-left",
            format : 'yyyy-mm-dd hh:mm'
        });
        $('.form_date_e').datetimepicker({
            language : 'zh-CN',
            weekStart : 1,
            todayBtn : 1,
            autoclose : 1,
            todayHighlight : 1,
            startView : 2,
            //minView: 2,
            forceParse : 0,
            pickerPosition : "bottom-left",
            format : 'yyyy-mm-dd hh:mm'
        });

        var myDate = new Date();
        var year = myDate.getFullYear();
        var month = myDate.getMonth() + 1;
        if(month<10){
            month='0'+month;
        }
        var date = myDate.getDate();
        if(date<10){
            date='0'+date;
        }
        $('#date_ip_s').val(year + '-' + month + '-' + date + " 00:00");
        $('#date_ip_e').val(year + '-' + month + '-' + date + " 23:59");
        ////////////////////////初始化时间控件  end/////////////////////

        ////////////////////////初始化页面元素事件  start/////////////////////
        $("#time-quick a").click(function(){
            var text=$(this).html();
            timeBtnObj.html(text);
            queryFun();
        });

        timeBtnObj.click(function(){
            $('#timeselect').toggle();
        });
        $("#btn-timego").click(function(){
            var ts=$('#date_ip_s').val();
            var te=$('#date_ip_e').val();
            timeBtnObj.html(ts+"~"+te);
            queryFun();
        });

        $("#img-upchange").click(function(){
            $('#timeselect').toggle();
        });

        $("#li-q").click(function(){
            $('#time-absolute').hide();
            $('#time-quick').show();
            $('#li-q').addClass('active');
            $('#li-s').removeClass('active');
        });
        $("#li-s").click(function(){
            $('#time-absolute').show();
            $('#time-quick').hide();
            $('#li-s').addClass('active');
            $('#li-q').removeClass('active');
        });
        ////////////////////////初始化页面元素事件  end/////////////////////"
    };
    /**
     * 系统树控件初始化
     * @param timeBtnObj
     * @param queryFun
     */
    common.sysTreeInit=function(sysTreeObj,queryFun,type){
        sysTreeObj.jstree({
            'core' : {
                "animation" : 0,
                "check_callback" : true,
                "themes" : { "stripes" : true },
                "data" : {
                    "dataType": 'json',
                    "url":function(node){
                        var nodeId=node.id;
                        if(nodeId== '#'){
                            return "getRootNode.action";
                        }else{
                            return "getChildrenNode.action?type="+type;
                        }
                    },
                    "data":function(node){
                        var id=node.id;
                        var ref = sysTreeObj.jstree(true);
                        if(id=='1'){
                            return {"id" : node.id};
                        }else if(id.split("-").length==2){
                            return {"id" : node.id,"sysName":node.text};
                        }else if(id.split("-").length==3){
                            var sysId=ref.get_parent(node);
                            var sysNode=ref.get_node(sysId);
                            return {"id" : node.id,"sysName":sysNode.text,"l1Name":node.text};
                        }else if(id.split("-").length==4){
                            var l1Id=ref.get_parent(node);
                            var l1Node=ref.get_node(l1Id);
                            var sysId=ref.get_parent(l1Node);
                            var sysNode=ref.get_node(sysId);
                            return {"id" : node.id,"sysName":sysNode.text,"l1Name":l1Node.text,"l2Name":node.text};
                        }else{
                            return {"id" : node.id};
                        }
                    }
                }
            }
        }).bind('select_node.jstree', function (event, data) {
                var sysNameOut="";
                var l1NameOut="";
                var l2NameOut="";
                var l3NameOut="";
                var node=data.node;
                var id = data.node.id;
                var text = data.node.text;
                var ref = sysTreeObj.jstree(true);
                if(id=='1'){
                    sysNameOut="";
                    l1NameOut="";
                    l2NameOut="";
                    l3NameOut="";
                }else if(id.split("-").length==2){
                    sysNameOut=text;
                    l1NameOut="";
                    l2NameOut="";
                    l3NameOut="";
                }else if(id.split("-").length==3){
                    var sysId=ref.get_parent(node);
                    var sysNode=ref.get_node(sysId);
                    sysNameOut=sysNode.text;
                    l1NameOut=text;
                    l2NameOut="";
                    l3NameOut="";
                }else if(id.split("-").length==4){
                    var l1Id=ref.get_parent(node);
                    var l1Node=ref.get_node(l1Id);
                    var sysId=ref.get_parent(l1Node);
                    var sysNode=ref.get_node(sysId);
                    sysNameOut=sysNode.text;
                    l1NameOut=l1Node.text;
                    l2NameOut=text;
                    l3NameOut="";
                }else if(id.split("-").length==5){
                    var l2Id=ref.get_parent(node);
                    var l2Node=ref.get_node(l2Id);
                    var l1Id=ref.get_parent(l2Node);
                    var l1Node=ref.get_node(l1Id);
                    var sysId=ref.get_parent(l1Node);
                    var sysNode=ref.get_node(sysId);
                    sysNameOut=sysNode.text;
                    l1NameOut=l1Node.text;
                    l2NameOut=l2Node.text;
                    l3NameOut=text;
                }
                queryFun(sysNameOut,l1NameOut,l2NameOut,l3NameOut);
            });
    };

    /**
     * 系统树控件初始化
     * @param timeBtnObj
     * @param queryFun
     */
    common.fastdfsSysTreeInit=function(sysTreeObj,queryFun,type,fileType){
        sysTreeObj.jstree({
            'core' : {
                "animation" : 0,
                "check_callback" : true,
                "themes" : { "stripes" : true },
                "data" : {
                    "dataType": 'json',
                    "url":function(node){
                        var nodeId=node.id;
                        if(nodeId== '#'){
                            return "getRootNode.action";
                        }else{
                            return "getChildrenNode.action?type="+type+"&fileType="+fileType;
                        }
                    },
                    "data":function(node){
                        var id=node.id;
                        var ref = sysTreeObj.jstree(true);
                        if(id=='1'){
                            return {"id" : node.id};
                        }else if(id.split("-").length==2){
                            return {"id" : node.id,"sysName":node.text};
                        }else if(id.split("-").length==3){
                            var sysId=ref.get_parent(node);
                            var sysNode=ref.get_node(sysId);
                            return {"id" : node.id,"sysName":sysNode.text,"l1Name":node.text};
                        }else if(id.split("-").length==4){
                            var l1Id=ref.get_parent(node);
                            var l1Node=ref.get_node(l1Id);
                            var sysId=ref.get_parent(l1Node);
                            var sysNode=ref.get_node(sysId);
                            return {"id" : node.id,"sysName":sysNode.text,"l1Name":l1Node.text,"l2Name":node.text};
                        }else{
                            return {"id" : node.id};
                        }
                    }
                }
            }
        }).bind('select_node.jstree', function (event, data) {
                var sysNameOut="";
                var l1NameOut="";
                var l2NameOut="";
                var l3NameOut="";
                var node=data.node;
                var id = data.node.id;
                var text = data.node.text;
                var ref = sysTreeObj.jstree(true);
                if(id=='1'){
                    sysNameOut="";
                    l1NameOut="";
                    l2NameOut="";
                    l3NameOut="";
                }else if(id.split("-").length==2){
                    sysNameOut=text;
                    l1NameOut="";
                    l2NameOut="";
                    l3NameOut="";
                }else if(id.split("-").length==3){
                    var sysId=ref.get_parent(node);
                    var sysNode=ref.get_node(sysId);
                    sysNameOut=sysNode.text;
                    l1NameOut=text;
                    l2NameOut="";
                    l3NameOut="";
                }else if(id.split("-").length==4){
                    var l1Id=ref.get_parent(node);
                    var l1Node=ref.get_node(l1Id);
                    var sysId=ref.get_parent(l1Node);
                    var sysNode=ref.get_node(sysId);
                    sysNameOut=sysNode.text;
                    l1NameOut=l1Node.text;
                    l2NameOut=text;
                    l3NameOut="";
                }else if(id.split("-").length==5){
                    var l2Id=ref.get_parent(node);
                    var l2Node=ref.get_node(l2Id);
                    var l1Id=ref.get_parent(l2Node);
                    var l1Node=ref.get_node(l1Id);
                    var sysId=ref.get_parent(l1Node);
                    var sysNode=ref.get_node(sysId);
                    sysNameOut=sysNode.text;
                    l1NameOut=l1Node.text;
                    l2NameOut=l2Node.text;
                    l3NameOut=text;
                }
                queryFun(sysNameOut,l1NameOut,l2NameOut,l3NameOut);
            });
    };

    common.warning=function(msg){
        $("#id-tips").css({"bottom":"0px","left":"15%"});
        $("#id-tips").html("<strong style='color:red'>警告!</strong>"+"<span style='color:red'>"+msg+"</span>");
        $("#id-tips").fadeIn();
        setTimeout(function(){
            $("#id-tips").fadeOut();
        },2000);
    };

    common.tips =function(msg){
        $("#id-tips").css({"bottom":"0px","left":"15%"});
        $("#id-tips").html("<strong>提示!</strong>"+msg);
        $("#id-tips").fadeIn();
        setTimeout(function(){
            $("#id-tips").fadeOut();
        },2000);
    };
	window.common = window.common || common;
}());

//
$(function(){
	//$('.c_serverP').click();
}); 

// 左边菜单用
(function() {
	'use strict'
	var aside = $(document.body).find('.aside-wrap .navi>.nav');
	aside.children().each(function() {
		var o = $(this);
		$(this).children('a').click(function() {
			o.toggleClass("active");
		});
		o.children('ul').children().each(function() {
			$(this).click(function() {
				removeActive();
				$(this).addClass("active");
			});
		});
	});

	function removeActive() {
		aside.children().each(function() {
			$(this).children('ul').children().each(function() {
				$(this).removeClass("active")
			})
		})
	}

}());

function loginOut() {
	$.ajax({
		url : 'loginOut.action',// 跳转到 action
		type : 'post',
		cache : false,
		dataType : 'text',
		success : function(data) {
			if (data == 'success') {
				window.location.href = "login.jsp";
			}
		},
		error : function() {
			alert("异常！");
		}
	});
}
function onMenuChange(url) {
	if (url == "") {
		$('#content').html('');
		return;
	}
	common.go($('#content'), url);
}

function loadHtml(divId,url){
    $("#"+divId).load(url);
}


